package com.k.demo.service.impl;

import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.k.demo.entity.ConstantTerm;
import com.k.demo.entity.ConstantTermKind;
import com.k.demo.mapper.ConstantTermMapper;
import com.k.demo.service.ConstantTermService;


@Service
public class ConstantTermServiceImpl implements ConstantTermService {
	
	@Autowired
	private ConstantTermMapper constantTermMapper;

	//查找全部
	public List<ConstantTerm> getAll() {
		
		return constantTermMapper.getAll();
	}

	//根据id查找
	public ConstantTerm getById(int id) {
		
		return constantTermMapper.getById(id);
	}

	//根据对象查找
	public List<ConstantTerm> getByConstantTerm(ConstantTerm constantTerm) {
		
		return constantTermMapper.getConstantTerm(constantTerm);
	}

	//根据id假删除
	public int falseDeleteById(int id) {
		
		int count = constantTermMapper.falseDeleteById(id);
		
		if(count > 0) {
			
			return count;
			
		}
		
		return 0;
	}

	//根据id真删除
	public int trueDeleteById(int id) {
		
		int count = constantTermMapper.trueDeleteById(id);
		
		if(count> 0) {
			
			return count;
			
		}
		
		return 0;
	}

	//批量删除
	public boolean deletByGroup(List<Integer> list) {
		
		return constantTermMapper.deleteByGroup(list);
	}

	//修改
	public ConstantTerm modifyConstantTerm(ConstantTerm constantTerm) {
		
		int count = constantTermMapper.modifyConstantTerm(constantTerm);
		
		if(count > 0) {
			
			return constantTerm;
			
		}
		
		return null;
	}

	//@增加
	public ConstantTerm addConstantTerm(ConstantTerm constantTerm) {
		
		int count = constantTermMapper.addConstantTerm(constantTerm);
		
		if(count > 0) {
			
			return constantTerm;
			
		}
		return null;
	}

	//分页显示所有
	public PageInfo<ConstantTerm> getPage(int pageNum, int pageSize) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<ConstantTerm>(constantTermMapper.getAll());
	}

	//查找结果并分页显示
	public PageInfo<ConstantTerm> getPageByConstantTerm(int pageNum, int pageSize, ConstantTerm constantTerm) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<ConstantTerm>(constantTermMapper.getConstantTerm(constantTerm));
	}

	//根据常数项类别查找
	public List<ConstantTerm> getByConstantTermKind(int constant_term_kind) {
		
		return constantTermMapper.getByConstantTermKind(constant_term_kind);
	}

}
